# -*- coding: utf-8 -*-
from core import YamlLoad
from core.DataReplace import data_processing
from core.Response import HttpResponse
from core.session import HttpRequest
from config.config import log_separator
from utils.logger import log

"""
测试用例统一执行方法
"""


def run_test(data):
    data = data_processing(data)
    temp = HttpRequest()
    # 发送http请求
    response = temp.session_request(data)
    # 处理响应信息
    log.info(log_separator + "Response processing" + log_separator)
    res = HttpResponse(response, temp.response_time_ms)
    # 提取数据到extract文件中
    extract = data.get("extract")
    if extract != "None" and extract:
        extract_data = res.extract_value(extract)
        if extract_data:
            YamlLoad.write_center_params(extract_data)
    # 断言的处理
    validate_list = data.get("validate")
    if validate_list != "None" and validate_list:
        result = res.validate(validate_list)
        return result
    log.info(log_separator + "end" + log_separator + '\n\n')
